<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/10/13/013
  Time: 16:43
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>评论管理</title>
    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.0.min.js"></script>
    <script>
        function deleteUser(com_id){
            //1.弹窗提示
            let pageFlag="${sessionScope.pageFlag}";
            if(confirm("确定要删除该评论吗？")){
                if (pageFlag=="commentListFlag"){
                    location.href= "${pageContext.request.contextPath}/commentAdmin/deleteComment?com_id="+com_id+"&&total=${requestScope.commentAdminLimit.getTotal()}&&num=${requestScope.commentAdminLimit.getNum()}&&currentPage=${requestScope.commentAdminLimit.getCurrentPage()}";
                }else if (pageFlag=="findCommentByTimeQuantumFlag"){
                    location.href= "${pageContext.request.contextPath}/commentAdmin/deleteComment?com_id="+com_id+"&&timeQuantum=${requestScope.timeQuantum}";
                }else {
                    location.href= "${pageContext.request.contextPath}/commentAdmin/deleteComment?com_id="+com_id+"&&userInfo=${requestScope.userInfo}";
                }
            }
        };
        $(function (){
            let pageFlag="${sessionScope.pageFlag}";
            let list="${requestScope.list}";
            if (pageFlag=="commentListFlag"){
                $("#totleDiv").prop('hidden', false);
            }
        });
        $(function (){
            $("#deletSelected").click(function (){
                let pageFlag="${sessionScope.pageFlag}";
                var selectFlag = false;
                if(confirm("确定要删除选中的评论吗?")){
                    if (pageFlag=="commentListFlag"){
                        $("#form").attr("action","${pageContext.request.contextPath}/commentAdmin/deleteSelectComment?total=${requestScope.commentAdminLimit.getTotal()}&&num=${requestScope.commentAdminLimit.getNum()}&&currentPage=${requestScope.commentAdminLimit.getCurrentPage()}");
                    }else if (pageFlag=="findCommentByTimeQuantumFlag"){
                        $("#form").attr("action","${pageContext.request.contextPath}/commentAdmin/deleteSelectComment?timeQuantum=${requestScope.timeQuantum}");
                    }else {
                        $("#form").attr("action","${pageContext.request.contextPath}/commentAdmin/deleteSelectComment?userInfo=${requestScope.userInfo}");
                    }
                    var cbs=document.getElementsByName("com_id");
                    for (var i=0;i<cbs.length;i++){
                        if (cbs[i].checked){
                            selectFlag = true;
                            break;
                        }
                    }
                }
                if(selectFlag){
                    $("#form").submit();
                }
            });
            $("#first").click(function (){
                //3.1确定全选按钮的选中状态
                var flag = $(this).prop("checked");
                //3.2让所有的checkBox的选中状态 = flag
                $(".first-item").prop("checked",flag);
            });
            $("#byUserId").click(function (){
                var infoFlag = false;

                if ($("#userInfo").val()!=""){
                    infoFlag = true;
                }else {
                    alert("请输入要查询的用户Id值！")
                }
                    if (infoFlag==true){
                        $("#commentSearch").attr("action","${pageContext.request.contextPath}/commentAdmin/findCommentByUserId");
                        $("#commentSearch").submit();
                    }
            });
            $("#byAdminId").click(function (){
                var infoFlag = false;
                if ($("#userInfo").val()!=""){
                    infoFlag = true;
                }else {
                    alert("请输入要查询的动漫Id值！")
                }
                if (infoFlag==true){
                    $("#commentSearch").attr("action","${pageContext.request.contextPath}/commentAdmin/findCommentByAdminId");
                    $("#commentSearch").submit();
                }
            });
            $("#allComment").click(function (){
                    $("#commentSearch").attr("action","${pageContext.request.contextPath}/admin/commentAdmin");
                    $("#commentSearch").submit();
            });
            $("#topComment").click(function (){
                var infoFlag = false;
                if ($("#userInfo").val()==null || $("#userInfo").val()==""){
                    alert("您未输入需要查询的个数，默认显示前三！");
                    $("#userInfo").val(3);
                    infoFlag = true;
                }else {
                    infoFlag = true;
                }
                if (infoFlag==true){
                    $("#commentSearch").attr("action","${pageContext.request.contextPath}/commentAdmin/findTopCommentByLikeNum");
                    $("#commentSearch").submit();
                }
            });
            $("#byTime").click(function (){
                $("#commentSearch").attr("action","${pageContext.request.contextPath}/commentAdmin/findCommentByTimeQuantum?timeQuantum="+$("#timeQuantum").val());
                $("#commentSearch").submit();
            });

            $("#nextPageBtn").click(function (){
                if ($("#nextPageBtnLi").prop("class")!="disabled"){
                    currentPage=${requestScope.commentAdminLimit.getCurrentPage()}+1;
                    location.href="${pageContext.request.contextPath}/commentAdmin/commentAdminPageJump?total=${requestScope.commentAdminLimit.getTotal()}&&num=${requestScope.commentAdminLimit.getNum()}&&currentPage="+currentPage;
                }else {
                    alert("这已经是最后一页了！");
                }

            });
            $(".commentPages").click(function (){
                currentPage=$(this).html();
                location.href="${pageContext.request.contextPath}/commentAdmin/commentAdminPageJump?total=${requestScope.commentAdminLimit.getTotal()}&&num=${requestScope.commentAdminLimit.getNum()}&&currentPage="+currentPage;
            });
            $("#perPageBtn").click(function (){
                if ($("#perPageBtnLi").prop("class")!="disabled"){
                    currentPage=${requestScope.commentAdminLimit.getCurrentPage()}-1;
                    location.href="${pageContext.request.contextPath}/commentAdmin/commentAdminPageJump?total=${requestScope.commentAdminLimit.getTotal()}&&num=${requestScope.commentAdminLimit.getNum()}&&currentPage="+currentPage;
                }else {
                    alert("这已经是第一页了！");
                }
            });
        });

    </script>
</head>

<body>
<div class="container">
    <div class="row"><c:import url="component/header.jsp"></c:import></div><br><br><br>
    <h1>评论管理系统</h1>
    <div class="row">
        <form id="commentSearch" class="navbar-form navbar-left" role="search" action="">
            <div class="alert alert-info alert-dismissible" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <strong>操作提示：</strong> 在输入框输入用户uid/动漫aid后，点击对应按钮即可查看该用户的评论/属于动漫的评论！若要找点赞最多的N条评论，请输入后再点按钮！
            </div>
            <div class="form-group">
                <input type="text" class="form-control" id="userInfo" name="userInfo" placeholder="请输入用户uid/动漫aid">
            </div>
            <button id="byAdminId" type="" class="btn btn-default">搜索动漫评论</button>
            <button id="byUserId" type="" class="btn btn-default">搜索用户评论</button>
            <button id="allComment" type="" class="btn btn-default">查看所有评论</button>
            <button id="topComment" type="" class="btn btn-warning">查看点赞最多的评论</button>
            <a type="button" id="deletSelected" class="btn btn-danger">删除选中</a>
            <div class="form-group">
                <label for="timeQuantum">选择时间：</label>
                <select name="timeQuantum" class="form-control" id="timeQuantum">
                    <option value="365000">所有</option>
                    <option value="3">三天内</option>
                    <option value="7">七天内</option>
                    <option value="15">十五天内</option>
                    <option value="30">一个月内</option>
                    <option value="182">半年内</option>
                    <option value="365">一年内</option>
                </select>
            </div>
            <button id="byTime" type="" class="btn btn-default">搜索最近评论</button>
        </form>

    </div>
    <form id="form" action="" method="post">
        <table border="1" class="table table-bordered table-hover table-striped" >
            <tr class="default">
                <th><input type="checkbox" id="first"></th>
                <th>编号</th>
                <th>内容</th>
                <th>点赞人数</th>
                <th>评论时间</th>
                <th>分数</th>
                <th>隶属动漫id</th>
                <th>隶属用户id</th>
                <th>操作</th>
            </tr>
            <%--
               items:从哪个域对象中取出数据 -> list
               varStatus:
                  count:表示循环次数
            --%>
            <c:forEach items="${requestScope.list}" var="comment" varStatus="s">
                <tr>
                    <td><input class="first-item" type="checkbox" name="com_id" value="${comment.com_id}"></td>
                    <td>${s.count}</td>
                    <td>${comment.context}</td>
                    <td>${comment.like_num}</td>
                    <td>${comment.create_time}</td>
                    <td>${comment.score}</td>
                    <td>${comment.aid}</td>
                    <td>${comment.uid}</td>
                    <td>
                        <a class="btn btn-default btn-sm" href="javascript:deleteUser(${comment.com_id})">删除</a>
                    </td>
                </tr>
            </c:forEach>
        </table>
        <div class="col-md-3" style="float: right;font-size: 15px;" id="totleDiv" hidden="hidden">
            <p style="float: right;font-size: 15px;}">全站所有评论数据当前共:${requestScope.commentAdminLimit.total}条</p>
        </div>
    </form>
    <ul class="pagination" id="commentAdminLimit">
        <li id="perPageBtnLi" class="${requestScope.commentAdminLimit.hasPre() ? "" : "disabled"}"><a class="button" id="perPageBtn">上一页</a></li>
        <c:forEach items="${requestScope.commentAdminLimit.pages}" var="item">
            <li class="${requestScope.commentAdminLimit.currentPage == item ? "active" : ""}"><a class="commentPages">${item}</a></li>
        </c:forEach>
        <li id="nextPageBtnLi" class="${requestScope.commentAdminLimit.hasNext() ? "" : "disabled"}"><a class="button" id="nextPageBtn">下一页</a></li>

    </ul>
</div>

</body>
</html>
